<?php

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

function displayRoster($guild_id)
{
	$db =& JFactory::getDBO();
	$query = "SELECT * FROM ".$db->nameQuote('#__guild_players')." WHERE `guild_id` = '$guild_id'";
	$db->setQuery($query);
	$rowx = $db->loadAssocList();
	/*
	echo '<pre>';
	print_r($row);
	echo '</pre><br>';
	*/

	$row=array();
	foreach ($rowx as $index => $member)
	{
		$row[$index]=array();

			$ii = playerthumb($member);
			$link = playerlink($member);
			//'.JRoute::_('index.php?option=com_pbroster&view=character&ch='.$member['member_id'].'&loc='.$member['region'])
			$row[$index]['name'] = ''.$ii.'<a href="index.php?option=com_pbroster&view=character&ch='.$member['member_id'].'&loc='.$member['region'].'">'.$member['name'].'</a>';//($member[ $aColumns[$i] ]=="0") ? '-' : $member[ $aColumns[$i] ];

			$ee = racethumb($member);
			$row[$index]['race'] = $ee.' '.$member['race'];
			$row[$index]['level'] = $member['level'];

			/* Special output formatting for 'version' column */
			$row[$index]['class'] = class_value( $member, $member['member_id'] );
			//'<a href="index.php?p=info&amp;name='.$member['name'].'&amp;server='.$member['server'].'">'.$member['name'].'</a>';
			//($member[ $aColumns[$i] ]=="0") ? '-' : $member[ $aColumns[$i] ];

			$row[$index]['update'] = date("M d Y H:i:s", $member['dateupdatedutc']);//dateupdatedutc

			/* General output */
			//$row[$index][$aColumns[$i]] = $member[ $aColumns[$i] ];
	}
	//echo '<pre>';
	//print_r($row);
	//echo '</pre>';
	
	echo '<div class="container"><table cellpadding="0" cellspacing="0" border="0" class="display">';
	echo '<tr class="membersRow1">
	<td width="130px">Name</td>
	<td width="100px">Race</td>
	<td width="40px">Level</td>
	<td width="120px">Class</td>
	<td width="150px">Updated</td></tr>';
	foreach ($row as $id => $member)
	{
		echo '<tr class="membersRow1"><td>'.$member['name'].'</td>';
		echo '<td>'.$member['race'].'</td>';
		echo '<td>'.$member['level'].'</td>';
		echo '<td>'.$member['class'].'</td>';
		echo '<td>'.$member['update'].'</td></tr>';
	}
	echo '</table></div>';


}

function playerthumb($row)
{
	$region = strtolower($row['region']);
	if ($row['level'] > 10)
	{
		$img = 'http://'.$region.'.battle.net/static-render/'.$region.'/' . $row['thumbnail'];
	}
	else
	{
		$img = ''.getRosterPath("images").'avatars/default/' . $row['raceid'] . '-' . $row['sexid'] . '.jpg';
	}
	
	
	$icon = '<img src="' . $img . '" alt="" width="20" height="20" style="vertical-align: middle;padding-right: 4px;"/>';
	
	return $icon;
}

function playerlink($row)
{
	if ($row['level'] > 10)
	{
		$link = '<a href="index.php?p=info&amp;c='.$row['member_id'].'&loc='.$row['region'].'"><font color="'.$lang['class_colorArray'][$row['classid']].'">'.$row['name'].'</font></a>';
	}
	else
	{
		$link = '<font color="'.$lang['class_colorArray'][$row['classid']].'">'.$row['name'].'</font>';
	}

	return $link;
}

function racethumb($row)
{

	$icon = '<img src="'.getRosterPath("images").'icons/races/small/' . $row['raceid'] . '-' . $row['sexid'] . '.jpg" alt="" width="20" height="20" style="vertical-align: middle;padding-right: 4px;"/>';
	
	return $icon;
}


	function class_value ( $row, $field )
	{
		global $roster, $addon;

		$lang = array('class_colorArray' => array(
			6=>'C41F3B',
			11 => 'FF7D0A',
			3 => 'ABD473',
			8 => '69CCF0',
			2 => 'F58CBA',
			5 => 'FFFFFF',
			4 => 'FFF569',
			7 => '2459FF',
			9 => '9482C9',
			1 => 'C79C6E'),
		'class_iconArray' => array (
			6=>'deathknight_icon',
			11=>'druid_icon',
			3=>'hunter_icon',
			8=>'mage_icon',
			2=>'paladin_icon',
			5=>'priest_icon',
			4=>'rogue_icon',
			7=>'shaman_icon',
			9=>'warlock_icon',
			1=>'warrior_icon'),
		);
	
		if( $row['class'] != '' )
		{
			$icon_value = '';

				$icon_name = $lang['class_iconArray'][$row['classid']];
				$icon_value .= '<div style="display: block;float:left;font:bold 13px arial,helvetica,sans-serif;">
				<img src="'.getRosterPath("images").'icons/classes/' . $icon_name . '.jpg" alt="" width="20" height="20" style="vertical-align: middle;padding-right: 4px;"/>';

				$fieldtext = $row['class'];
				return '' . $icon_value . '<font color="'.$lang['class_colorArray'][$row['classid']].'">' . $fieldtext . '</font></div>';

		}
		else
		{
			return '&nbsp;';
		}
	}
	
	
	function getRosterPath($option) {
  $path = "";
  switch ($option) {
      case 'base':   $path = JUri::root(true);  break;
      case 'path':   $path = JUri::root();  break;
	  case 'roster': $path = JUri::root().'components/com_pbroster/';  break;
	  case 'emblem': $path = JUri::root().'components/com_pbroster/guild_emblem/';  break;
      case 'images': $path = JUri::root().'components/com_pbroster/images/';  break;
	  default:       $path = JUri::root();  break;
    }
    return $path;
}


?>